package com.shanghaionstar.utils;

import android.content.Context;

import com.onstar.cn.common.IServerUrls;
import com.onstar.cn.common.bean.EnvMode;
import com.onstar.cn.common.util.Constants;
import com.onstar.cn.common.util.EncryptUtil;
import com.onstar.cn.common.util.PreferencesUtls;
import com.onstar.cn.framework.network.entity.SSLConnectionFactory;


/**
 * Created by kai zhang on 2015/12/17.
 */
public class DevelopServerEnvironmentUtil {

    private String[] modes;

    private static class Inner {
        static DevelopServerEnvironmentUtil util = new DevelopServerEnvironmentUtil();
    }

    private DevelopServerEnvironmentUtil() {
    }

//    public synchronized String[] getModes() {
//        if (modes == null) {
//            modes = new String[MODE.values().length];
//            for (int i = 0; i < modes.length; i++) {
//                modes[i] = MODE.values()[i].name();
//            }
//        }
//        return modes;
//    }

    public final static DevelopServerEnvironmentUtil getInstance() {
        return Inner.util;
    }

    public boolean isDevelopMode(Context context) {
        return FinalConfigParams.TRUE.equals(IServerUrls.isDevelopMode);
    }

    public String getServerUrl(Context context) {
        return PreferencesUtls.getInstance(context).getString(Constants.DEV_SERVER_URL);
    }

    public String getAuthServerUrl(Context context) {
        return PreferencesUtls.getInstance(context).getString(FinalConfigParams.DEV_AUTHSERVERURL);
    }

    public String getResetPwdUrl(Context context) {
        return PreferencesUtls.getInstance(context).getString(Constants.DEV_RESETPWD_URL);
    }

    public int getCurrentEnvironmentMode(Context context) {
        return Constants.CURRENT_ENV;
    }

    public void setEnvironmentMode(int mode, Context context) {
//        PreferencesUtls.getInstance(context).putInt(FinalConfigParams.ENVIRONMENT, mode);
//        String pwdUrl = null, serverUrl = null, authServerUrl = null;
        switch (mode) {
            case EnvMode.IDT1:
//                pwdUrl = BusinessUtil.getConfigValue(JoinMeConstants.resetPassword_idt1, context);
//                serverUrl = BusinessUtil.getConfigValue(Constants.IDT1_SERVER_URL, context);
//                authServerUrl = BusinessUtil.getConfigValue(Constants.IDT1_AUTH_SERVER_URL, context);
                Constants.CURRENT_SERVER_URL = EncryptUtil.decryptBase64(context, IServerUrls.idt1ServerURL);
                Constants.CURRENT_AUTH_URL = EncryptUtil.decryptBase64(context, IServerUrls.idt1AuthServerURL);

                Constants.CURRENT_PREFIX_H5_URL = EncryptUtil.decryptBase64(context, Constants.PREFIX_H5_URL_IDT1);
                Constants.CAR_ASSESSMENT = Constants.CAR_ASSESSMENT_DEFAULT;
                Constants.DRIVE_SCORE = Constants.DRIVE_SCORE_DEFAULT;
                Constants.URL_DAAP_REPORT = Constants.DAAP_REPORT_URL_IDT1;
                SSLConnectionFactory.capInputNames = SSLConnectionFactory.CAPINPUTNAMES_IDT1;
                JoinMeConstants.reset_password_url = EncryptUtil.decryptBase64(context, IServerUrls.resetPassword_idt1);
                Constants.VDFORO_URL_CURRENT = EncryptUtil.decryptBase64(context, Constants.VDFORO_URL_TEST);
                Constants.CURRENT_PREFIX_USER_GUIDE_URL = EncryptUtil.decryptBase64(context, Constants.PREFIX_USER_GUIDE_URL_IDT1);

                break;
            case EnvMode.IDT2:
//                pwdUrl = BusinessUtil.getConfigValue(JoinMeConstants.resetPassword_qa, context);
//                serverUrl = BusinessUtil.getConfigValue(Constants.IDT2_SERVER_URL, context);
//                authServerUrl = BusinessUtil.getConfigValue(Constants.IDT2_AUTH_SERVER_URL, context);
                Constants.CURRENT_SERVER_URL = EncryptUtil.decryptBase64(context, IServerUrls.idt2ServerURL);
                Constants.CURRENT_AUTH_URL = EncryptUtil.decryptBase64(context, IServerUrls.idt2AuthServerURL);


                Constants.CAR_ASSESSMENT = Constants.CAR_ASSESSMENT_DEFAULT;
                Constants.DRIVE_SCORE = Constants.DRIVE_SCORE_DEFAULT;
//                JoinMeConstants.reset_password_url = EncryptUtil.decryptBase64(context, IServerUrls.resetPassword_idt1);

                break;
            case EnvMode.PRODUCT:
//                pwdUrl = BusinessUtil.getConfigValue(JoinMeConstants.resetPassword_product, context);
//                serverUrl = BusinessUtil.getConfigValue(Constants.PRODUCT_SERVER_URL, context);
//                authServerUrl = BusinessUtil.getConfigValue(Constants.PRODUCT_AUTH_SERVER_URL, context);
                Constants.CURRENT_SERVER_URL = EncryptUtil.decryptBase64(context, IServerUrls.productServerURL);
                Constants.CURRENT_AUTH_URL = EncryptUtil.decryptBase64(context, IServerUrls.productAuthServerURL);

                Constants.CURRENT_PREFIX_H5_URL = EncryptUtil.decryptBase64(context, Constants.PREFIX_H5_URL_PROD);
                Constants.CAR_ASSESSMENT = Constants.CAR_ASSESSMENT_DEFAULT;
                Constants.DRIVE_SCORE = Constants.DRIVE_SCORE_DEFAULT;
                SSLConnectionFactory.capInputNames = SSLConnectionFactory.CAPINPUTNAMES_PROD;
                JoinMeConstants.reset_password_url = EncryptUtil.decryptBase64(context, IServerUrls.resetPassword_product);
                Constants.VDFORO_URL_CURRENT = EncryptUtil.decryptBase64(context, Constants.VDFORO_URL_PROD);
                Constants.CURRENT_PREFIX_USER_GUIDE_URL = EncryptUtil.decryptBase64(context, Constants.PREFIX_USER_GUIDE_URL);

                break;
            case EnvMode.PP2:
//                pwdUrl = BusinessUtil.getConfigValue(JoinMeConstants.resetPassword_pp2, context);
//                serverUrl = BusinessUtil.getConfigValue(Constants.PP2_SERVER_URL, context);
//                authServerUrl = BusinessUtil.getConfigValue(Constants.PP2_AUTH_SERVER_URL, context);
                Constants.CURRENT_SERVER_URL = EncryptUtil.decryptBase64(context, IServerUrls.pp2ServerURL);
                Constants.CURRENT_AUTH_URL = EncryptUtil.decryptBase64(context, IServerUrls.pp2AuthServerURL);

                Constants.CAR_ASSESSMENT = Constants.CAR_ASSESSMENT_DEFAULT;
                Constants.DRIVE_SCORE = Constants.DRIVE_SCORE_DEFAULT;
                JoinMeConstants.reset_password_url = EncryptUtil.decryptBase64(context, IServerUrls.resetPassword_pp2);

                break;
            case EnvMode.IDT5:
//                pwdUrl = BusinessUtil.getConfigValue(JoinMeConstants.resetPassword_idt5, context);
//                serverUrl = BusinessUtil.getConfigValue(Constants.IDT5_SERVER_URL, context);
//                authServerUrl = BusinessUtil.getConfigValue(Constants.IDT5_AUTH_SERVER_URL, context);
                Constants.CURRENT_SERVER_URL = EncryptUtil.decryptBase64(context, IServerUrls.idt5ServerURL);
                Constants.CURRENT_AUTH_URL = EncryptUtil.decryptBase64(context, IServerUrls.idt5AuthServerURL);

                Constants.CURRENT_PREFIX_H5_URL = EncryptUtil.decryptBase64(context, Constants.PREFIX_H5_URL_IDT5);
                Constants.CAR_ASSESSMENT = Constants.CAR_ASSESSMENT_DEFAULT;
                Constants.DRIVE_SCORE = Constants.DRIVE_SCORE_DEFAULT;
                JoinMeConstants.reset_password_url = EncryptUtil.decryptBase64(context, IServerUrls.resetPassword_idt5);

                break;
            case EnvMode.IDT4:
//                pwdUrl = BusinessUtil.getConfigValue(JoinMeConstants.resetPassword_idt4, context);
//                serverUrl = BusinessUtil.getConfigValue(Constants.IDT4_SERVER_URL, context);
//                authServerUrl = BusinessUtil.getConfigValue(Constants.IDT4_AUTH_SERVER_URL, context);
                Constants.CURRENT_SERVER_URL = EncryptUtil.decryptBase64(context, IServerUrls.idt4ServerURL);
                Constants.CURRENT_AUTH_URL = EncryptUtil.decryptBase64(context, IServerUrls.idt4AuthServerURL);

                Constants.CURRENT_PREFIX_H5_URL = EncryptUtil.decryptBase64(context, Constants.PREFIX_H5_URL_IDT4);
                Constants.CAR_ASSESSMENT = Constants.CAR_ASSESSMENT_DEFAULT;
                Constants.DRIVE_SCORE = Constants.DRIVE_SCORE_DEFAULT;
                JoinMeConstants.reset_password_url = EncryptUtil.decryptBase64(context, IServerUrls.resetPassword_idt4);

                break;
            case EnvMode.PP1:
//                pwdUrl = JoinMeConstants.resetPassword_pp1;
//                serverUrl = BusinessUtil.getConfigValue(Constants.PP1_SERVER_URL, context);
//                authServerUrl = BusinessUtil.getConfigValue(Constants.PP1_AUTH_SERVER_URL, context);
                Constants.CURRENT_SERVER_URL = EncryptUtil.decryptBase64(context, IServerUrls.pp1ServerURL);
                Constants.CURRENT_AUTH_URL = EncryptUtil.decryptBase64(context, IServerUrls.pp1AuthServerURL);

                Constants.CAR_ASSESSMENT = Constants.CAR_ASSESSMENT_DEFAULT;
                Constants.DRIVE_SCORE = Constants.DRIVE_SCORE_DEFAULT;

                break;
            case EnvMode.VV1:
//                pwdUrl = JoinMeConstants.resetPassword_vv1;
//                serverUrl = BusinessUtil.getConfigValue(Constants.VV1_SERVER_URL, context);
//                authServerUrl = BusinessUtil.getConfigValue(Constants.VV1_AUTH_SERVER_URL, context);
                Constants.CURRENT_SERVER_URL = EncryptUtil.decryptBase64(context, IServerUrls.vv1ServerURL);
                Constants.CURRENT_AUTH_URL = EncryptUtil.decryptBase64(context, IServerUrls.vv1AuthServerURL);

                Constants.CAR_ASSESSMENT = Constants.CAR_ASSESSMENT_DEFAULT;
                Constants.DRIVE_SCORE = Constants.DRIVE_SCORE_DEFAULT;

                break;
            case EnvMode.VV2:
//                pwdUrl = JoinMeConstants.resetPassword_vv1;
//                serverUrl = BusinessUtil.getConfigValue(Constants.VV1_SERVER_URL, context);
//                authServerUrl = BusinessUtil.getConfigValue(Constants.VV1_AUTH_SERVER_URL, context);
                Constants.CURRENT_SERVER_URL = EncryptUtil.decryptBase64(context, IServerUrls.vv2ServerURL);
                Constants.CURRENT_AUTH_URL = EncryptUtil.decryptBase64(context, IServerUrls.vv2AuthServerURL);

                Constants.CAR_ASSESSMENT = Constants.CAR_ASSESSMENT_DEFAULT;
                Constants.DRIVE_SCORE = Constants.DRIVE_SCORE_DEFAULT;
                SSLConnectionFactory.capInputNames = SSLConnectionFactory.CAPINPUTNAMES_VV2;

                break;
            default:
        }

        Constants.CURRENT_ENV = mode;
//        if (!CommonUtil.isNull(pwdUrl)) {
//            PreferencesUtls.getInstance(context).putString(Constants.DEV_RESETPWD_URL, pwdUrl);
//        }
//        if (!CommonUtil.isNull(serverUrl)) {
//            PreferencesUtls.getInstance(context).putString(Constants.DEV_SERVER_URL, serverUrl);
//        }
//        if (!CommonUtil.isNull(authServerUrl)) {
//            PreferencesUtls.getInstance(context).putString(FinalConfigParams.DEV_AUTHSERVERURL, authServerUrl);
//        }
//        if (!CommonUtil.isNull(Constants.PREFIX_H5_URL)) {
//            PreferencesUtls.getInstance(context).putString(FinalConfigParams.PREFIX_H5_URL, Constants.PREFIX_H5_URL);
//        }
    }
}
